渲染多个渲染通道或纹理
使用位块传送渲染通道 (Blit Render Pass) 位块传送多个合成目标渲染通道 (Composition Target Render Pass) 资源或纹理到使用特定材质的屏幕。默认情况下,位块传送渲染通道 (Blit Render Pass) 只使用一个合成目标渲染通道 (Composition Target Render Pass) 或纹理。
例如,您可以块传送多个渲染通道到使用特定材质的屏幕,以创建后期处理效果,如全屏泛光。请参阅教程:创建全屏泛光效果。
To render multiple render passes or textures:
- Modify the DefaultBlit material type to support blitting multiple textures:
- 在 素材库 (Library) > 材质和纹理 (Materials and Textures) > 材质类型 (Material Types) > DefaultBlit 中,双击 片段着色器 (Fragment Shader) 以在 着色器源编辑器 (Shader Source Editor) 中打开它。
建议如果您的工程不包含 DefaultBlit 材质类型,在素材库 (Library) > 材质和纹理 (Materials and Textures) 按下 Alt 并右键点击 材质类型 (Material Types) 中选择 DefaultBlit。
- 在 着色器源编辑器 (Shader Source Editor) 中,添加您希望 位块传送渲染通道 (Blit Render Pass) 使用的 uniform,并修改着色器以使用它们。
例如,要使着色器混合使用 Texture0 和 Texture1 属性,而自定义属性 Weight 用于在这两个属性之间进行衡量,请将着色器文件的内容替换为uniform sampler2D Texture0;
uniform sampler2D Texture1;
uniform mediump float Weight;
varying mediump vec2 vTexCoord;
void main()
{
precision lowp float;
gl_FragColor = mix(texture2D(Texture0, vTexCoord), texture2D(Texture1, vTexCoord), Weight);
}
点击保存 (Save)。 - 在素材库 (Library) > 材质和纹理 (Materials and Textures) > 材质类型 (Material Types) 中选择 DefaultBlit 材质类型并在属性 (Properties) 中点击同步 uniform (Sync with Uniforms) 以创建在片段着色器中定义的属性,并将其添加到材质类型和使用该类型的材质中。
- 在创建属性类型 (Create Property Type) 窗口中,点击是 (Yes) 以创建您用于在 Texture0 和 Texture1 属性之间进行衡量的自定义属性 Weight,在 属性类型编辑器 (Property Type Editor) 中将 默认值 (Default Value) 属性设为 0,5,然后点击 保存 (Save)。
- In the 素材库 (Library) > 材质和纹理 (Materials and Textures) > 材质 (Materials) select the DefaultBlitMaterial material,
which uses the DefaultBlit material type that you modified to support multiple textures, and in the 属性 (Properties) set the 混合模式 (Blend Mode) property to 阿尔法: 预乘 (Alpha: Premultiplied).
You set Kanzi to blend the textures that it blits on the screen using this material.
-
In the 素材库 (Library) 按下 Alt 并右键点击 渲染 (Rendering), and select Compose and Blit Pass.
Compose and Blit Pass template contains the render pass structure that enables you to blit to the screen 合成目标渲染通道 (Composition Target Render Pass) render passes or textures using a specific material. The template contains these render passes:- 合成目标渲染通道 (Composition Target Render Pass) 将自身及其子渲染通道渲染成合成目标。
- 清除渲染通道 (Clear Render Pass) clears some or all of the buffers of the current render context. By default the 清除渲染通道 (Clear Render Pass) in the Compose and Blit Pass template clears the color buffer with transparent black color and the depth buffer with value 1.
For example, to clear the color buffer with a different color, set the 清除颜色 (Clear Color) property to the color that you want to use as the background color of the content that Kanzi renders to the 合成目标渲染通道 (Composition Target Render Pass). - 绘图对象渲染通道 (Draw Objects Render Pass) allows you to set a 摄像机 (Camera) node to render a specific object source and to control frustum culling. By default the 绘图对象渲染通道 (Draw Objects Render Pass) uses the default 摄像机 (Camera) node to render all nodes in a 场景 (Scene) node.
- 位块传送渲染通道 (Blit Render Pass) 使用某种特定材质在屏幕上位块传送一个或多个渲染通道或纹理。 By default this 位块传送渲染通道 (Blit Render Pass) draws on the screen the content rendered by the 合成目标渲染通道 (Composition Target Render Pass).
- In the 工程 (Project) select the 场景 (Scene) node whose content you want to render to a composition target and in the 属性 (Properties) set the 渲染通道 (Render Pass) property to the Compose and Blit Pass.
Kanzi renders the content of that 场景 (Scene) node to a composition target and uses the Compose and Blit Pass > 位块传送渲染通道 (Blit Render Pass) to draw the content.
- In the 素材库 (Library) > 渲染 (Rendering) > 渲染通道 (Render Passes) select the Compose and Blit Pass > 位块传送渲染通道 (Blit Render Pass) and in the 属性 (Properties) add and set:
- Texture1 to a texture or a 合成目标渲染通道 (Composition Target Render Pass) that you want to use.
For example, add the Texture1 property and set it to a texture resource. - 材质 (Material) to the material that you want the 位块传送渲染通道 (Blit Render Pass) to use
For example, set it to the DefaultBlitMaterial material whose fragment shader you edited earlier in this procedure to make the material support mixing two textures. - Weight to the amount that you want to show each texture
To give more weight to Texture0, decrease the value of the Weight property, and to give more weight to Texture1, increase the value.
For example, set it to 0,5 to show the average of the textures set by the Texture0 and Texture1 properties.
另请参阅
教程:创建全屏泛光效果
渲染
使用材质类型
着色器
纹理
打开导航